﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebSimplicity.Data.Blog;
using System.Web.Helpers;

namespace WebSimplicity.Areas.Blog.Controllers
{
    public class PostsController : Controller
    {
        //ws_Website website = WebSite.GetWebsite();
        //
        // GET: /Admin/Posts/

        public ActionResult Index()
        {
            return View(Posts.GetPosts());
        }

        //
        // GET: /Admin/Posts/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Admin/Posts/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Admin/Posts/Create

        [HttpPost]
        public ActionResult Create(ws_Blog_Posts post)
        {
            FormCollection form = new FormCollection(Request.Unvalidated().Form);
            Posts.CreatePost(post, form);
            return RedirectToAction("index");
        }

        //
        // GET: /Admin/Posts/Edit/5

        public ActionResult Edit(int id)
        {
            return View(Posts.GetPost(id));
        }

        //
        // POST: /Admin/Posts/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, ws_Blog_Posts pst)
        {            
            FormCollection form = new FormCollection(Request.Unvalidated().Form);
            Posts.UpdatePost(id, pst, form);           
            return RedirectToAction("index");
        }

        //
        // GET: /Admin/Posts/Delete/5

        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Admin/Posts/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
